package com.gy.spark.core

import org.apache.spark.{SparkConf, SparkContext}

/**
 * 集群模式运行wc
 *
 */
object WordCountLocal2Cluster {

  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf()
      .setAppName(WordCountCluster.getClass.getSimpleName)
      .setMaster("spark://centos101:7077,centos102:7077")
      .setJars(Array("/Users/mac/Downloads/workspace/kkb-bigdata/target/kkb-bigdata-1.0-SNAPSHOT.jar"))

    val sc = new SparkContext(sparkConf)

    sc.setLogLevel("warn")

    sc.textFile(args(0))
      .flatMap(_.split(" "))
      .map((_, 1))
      .reduceByKey(_ + _)
      .sortBy(_._2, false)
      .saveAsTextFile(args(1))

    sc.stop()

  }


}
